{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import traceback\n",
    "import random\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "# import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    " def tail(f, lines=20):\n",
    "    total_lines_wanted = lines\n",
    "\n",
    "    BLOCK_SIZE = 1024\n",
    "    f.seek(0, 2)\n",
    "    block_end_byte = f.tell()\n",
    "    lines_to_go = total_lines_wanted\n",
    "    block_number = -1\n",
    "    blocks = []\n",
    "    while lines_to_go > 0 and block_end_byte > 0:\n",
    "        if (block_end_byte - BLOCK_SIZE > 0):\n",
    "            f.seek(block_number*BLOCK_SIZE, 2)\n",
    "            blocks.append(f.read(BLOCK_SIZE))\n",
    "        else:\n",
    "            f.seek(0,0)\n",
    "            blocks.append(f.read(block_end_byte))\n",
    "        lines_found = blocks[-1].count(b'\\n')\n",
    "        lines_to_go -= lines_found\n",
    "        block_end_byte -= BLOCK_SIZE\n",
    "        block_number -= 1\n",
    "    all_read_text = b''.join(reversed(blocks))\n",
    "    return b'\\n'.join(all_read_text.splitlines()[-total_lines_wanted:]).decode(\"utf-8\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_entries(dirname):\n",
    "    os.chdir(dirname)\n",
    "    data = {}\n",
    "    for entry in os.listdir():\n",
    "        if entry.startswith(\"a100\"):\n",
    "            entry_sp = entry.split(\"_\")\n",
    "            (gpu, job, topo, nnode_s, bw_s, deg_s, nlat_s, batch_s, njobs_s, nrun_s) = entry_sp\n",
    "#             print(entry_sp)\n",
    "            for innerdir in os.listdir(entry):\n",
    "                if innerdir.startswith(\"nwsim\"):\n",
    "                    with open(entry+\"/\"+innerdir, \"rb\") as nw:\n",
    "                        try:\n",
    "                            tailn = tail(nw, int(njobs_s))\n",
    "                            nums = [int(line.split(\" \")[1]) for line in tailn.split(\"\\n\") if \"Final\" in line]\n",
    "#                             print(nums)\n",
    "                            if (int(bw_s), int(njobs_s)) in data:\n",
    "                                data[int(bw_s), int(njobs_s)].extend(nums)\n",
    "                            else:\n",
    "                                data[int(bw_s), int(njobs_s)] = nums\n",
    "                        except:\n",
    "                            traceback.print_exception(*sys.exc_info())\n",
    "    for k,v in data.items():\n",
    "        data[k] = sorted(v)\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = get_entries(\"/home/gridsan/weiyangw/multijobs/fattree/job_load_abssw\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{(100, 15): [61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  210403519839,\n",
       "  210403519839,\n",
       "  210403519839,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661],\n",
       " (100, 5): [61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661],\n",
       " (800, 27): [24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  100481208562,\n",
       "  100481208562,\n",
       "  100481208562,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466],\n",
       " (400, 27): [20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745],\n",
       " (200, 20): [31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  131984682759,\n",
       "  131984682759,\n",
       "  131984682759,\n",
       "  131984682759,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626],\n",
       " (800, 20): [24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  100481208562,\n",
       "  100481208562,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466],\n",
       " (100, 10): [61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661],\n",
       " (200, 15): [31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  131984682759,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626],\n",
       " (100, 20): [61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  210403519839,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661],\n",
       " (800, 10): [24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  100481208562,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466],\n",
       " (400, 5): [20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  100481432902,\n",
       "  180967989745,\n",
       "  180967989745],\n",
       " (400, 15): [20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  100481432902,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745],\n",
       " (400, 10): [20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  100481432902,\n",
       "  100481432902,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745],\n",
       " (100, 27): [61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  61155050349,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  63968900177,\n",
       "  210403519839,\n",
       "  210403519839,\n",
       "  210403519839,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661,\n",
       "  512880309661],\n",
       " (400, 20): [20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  20779274436,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  61434284162,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745,\n",
       "  180967989745],\n",
       " (200, 5): [31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  131984682759,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626],\n",
       " (800, 15): [24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  100481208562,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466],\n",
       " (200, 10): [31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  131984682759,\n",
       "  131984682759,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626],\n",
       " (200, 27): [31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  31198235749,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  63239720177,\n",
       "  131984682759,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626,\n",
       "  301018471626],\n",
       " (800, 5): [24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  24747001831,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  60266186198,\n",
       "  129552720466,\n",
       "  129552720466,\n",
       "  129552720466]}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "os.chdir(\"/home/gridsan/weiyangw/multijobs/fattree/job_load_abssw\")\n",
    "for k, v in data.items():\n",
    "    with open(\"{:d}_fattree_{:d}jobs.csv\".format(k[0], k[1]), \"w\") as f:\n",
    "        for i in v:\n",
    "            f.write(str(i)+\"\\n\")\n",
    "    with open(\"{:d}_fattree_{:d}jobs_stat.csv\".format(k[0], k[1]), \"w\") as f:\n",
    "        avg_lat = sum(v)/len(v)\n",
    "        tail_lat_50 = v[int(0.50*len(v)) if int(0.90*len(v)) < len(v) else -1]\n",
    "        tail_lat_90 = v[int(0.90*len(v)) if int(0.90*len(v)) < len(v) else -1]\n",
    "        tail_lat_95 = v[int(0.95*len(v)) if int(0.95*len(v)) < len(v) else -1]\n",
    "        tail_lat_99 = v[int(0.99*len(v)) if int(0.99*len(v)) < len(v) else -1]\n",
    "        f.write(str(avg_lat)+\"\\n\")\n",
    "        f.write(str(tail_lat_90)+\"\\n\")\n",
    "        f.write(str(tail_lat_95)+\"\\n\")\n",
    "        f.write(str(tail_lat_99)+\"\\n\")\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = get_entries(\"/home/gridsan/weiyangw/multijobs/fattree/job_load_ft_32\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_topoopt_data(bw, deg):\n",
    "    jobtype = [\"dlrm\", \"transformer\", \"candle\", \"vggr\"]\n",
    "    chances = [0.35, 0.65, 0.9, 1]\n",
    "    os.chdir(\"/home/gridsan/weiyangw/multijobs/topoopt\")\n",
    "    njobs = [5, 10, 15, 20, 27]\n",
    "    data = {}\n",
    "    for n in njobs:\n",
    "        data[n] = []\n",
    "        for trials in range(5):\n",
    "            for m in range(n):\n",
    "                jobname = jobtype[next(i for i, x in enumerate(chances) if x > random.uniform(0, 1))]\n",
    "                data[n].append(sample_one(jobname, 16, bw, deg))\n",
    "    for k,v in data.items():\n",
    "        data[k] = sorted(v)\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sample_one(jname, nnode, bw, deg):\n",
    "    avail = list(range(5))\n",
    "    entries = get_entries_topoopt(\"/home/gridsan/weiyangw/multijobs/topoopt/\"+jname+str(nnode))\n",
    "    result = []\n",
    "    while len(result) == 0:\n",
    "        selrun = random.randint(0,4)\n",
    "#         print(selrun)\n",
    "        selected = filter(lambda e: int(e[4]) == bw and int(e[5]) == deg and int(e[-2]) == selrun, entries)\n",
    "        result = list(selected)\n",
    "#         print(result)\n",
    "    return result[0][-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_entries_topoopt(dirname):\n",
    "    os.chdir(dirname)\n",
    "    data = []\n",
    "    for entry in os.listdir():\n",
    "        if entry.startswith(\"a100\"):\n",
    "            entry_sp = entry.split(\"_\")\n",
    "            last_line = \"\"\n",
    "            for innerdir in os.listdir(entry):\n",
    "                if innerdir.startswith(\"nwsim\"):\n",
    "                    with open(entry+\"/\"+innerdir, \"rb\") as nw:\n",
    "                        try:\n",
    "                            nw.seek(-2, os.SEEK_END)\n",
    "                            while nw.read(1) != b'\\n':\n",
    "                                nw.seek(-2, os.SEEK_CUR)\n",
    "                            last_line = nw.readline().decode()\n",
    "                            if \"Final\" in last_line:\n",
    "                                entry_sp.append(int(last_line.split(\" \")[1][:-1]))\n",
    "                                data.append(entry_sp)\n",
    "                        except:\n",
    "                            pass\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "131546054758"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_entries_topoopt(\"/home/gridsan/weiyangw/multijobs/topoopt/vggr16\")\n",
    "sample_one(\"candle\", 16, 100, 8)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{5: [15185241946, 15185241946, 15185241946, 19926218536, 19926218536, 19926218536, 19926218536, 20917179248, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 131546054758, 131546054758], 10: [15185241946, 19382130971, 19382130971, 19611805047, 19611805047, 19611805047, 19611805047, 19926218536, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 100559060382, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758], 15: [15185241946, 15185241946, 15185241946, 15185241946, 15185241946, 15185241946, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 100559060382, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758], 20: [15185241946, 15185241946, 15185241946, 15185241946, 15185241946, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 100559060382, 100559060382, 100559060382, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758], 27: [15185241946, 15185241946, 15185241946, 15185241946, 15185241946, 15185241946, 19382130971, 19382130971, 19382130971, 19382130971, 19382130971, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19611805047, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 19926218536, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 20917179248, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 62643560175, 100559060382, 100559060382, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758, 131546054758]}\n"
     ]
    }
   ],
   "source": [
    "os.chdir(\"/home/gridsan/weiyangw/multijobs/topoopt\")\n",
    "topo_d8_16 = get_topoopt_data(100, 8)\n",
    "print(topo_d8_16)\n",
    "os.chdir(\"/home/gridsan/weiyangw/multijobs/topoopt\")\n",
    "for k, v in topo_d8_16.items():\n",
    "    with open(\"{:d}_topo_d8_{:d}jobs.csv\".format(100, k), \"w\") as f:\n",
    "        for i in v:\n",
    "            f.write(str(i)+\"\\n\")\n",
    "    with open(\"{:d}_topo_d8_{:d}jobs_stat.csv\".format(100, k), \"w\") as f:\n",
    "        avg_lat = sum(v)/len(v)\n",
    "        tail_lat_50 = v[int(0.50*len(v)) if int(0.90*len(v)) < len(v) else -1]\n",
    "        tail_lat_90 = v[int(0.90*len(v)) if int(0.90*len(v)) < len(v) else -1]\n",
    "        tail_lat_95 = v[int(0.95*len(v)) if int(0.95*len(v)) < len(v) else -1]\n",
    "        tail_lat_99 = v[int(0.99*len(v)) if int(0.99*len(v)) < len(v) else -1]\n",
    "        f.write(str(avg_lat)+\"\\n\")\n",
    "        f.write(str(tail_lat_90)+\"\\n\")\n",
    "        f.write(str(tail_lat_95)+\"\\n\")\n",
    "        f.write(str(tail_lat_99)+\"\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "topo_d4_16 = get_topoopt_data(100, 4)\n",
    "os.chdir(\"/home/gridsan/weiyangw/multijobs/topoopt\")\n",
    "for k, v in topo_d4_16.items():\n",
    "    with open(\"{:d}_topo_d4_{:d}jobs.csv\".format(100, k), \"w\") as f:\n",
    "        for i in v:\n",
    "            f.write(str(i)+\"\\n\")\n",
    "    with open(\"{:d}_topo_d4_{:d}jobs_stat.csv\".format(100, k), \"w\") as f:\n",
    "        avg_lat = sum(v)/len(v)\n",
    "        tail_lat_90 = v[int(0.90*len(v)) if int(0.90*len(v)) < len(v) else -1]\n",
    "        tail_lat_95 = v[int(0.95*len(v)) if int(0.95*len(v)) < len(v) else -1]\n",
    "        tail_lat_99 = v[int(0.99*len(v)) if int(0.99*len(v)) < len(v) else -1]\n",
    "        f.write(str(avg_lat)+\"\\n\")\n",
    "        f.write(str(tail_lat_90)+\"\\n\")\n",
    "        f.write(str(tail_lat_95)+\"\\n\")\n",
    "        f.write(str(tail_lat_99)+\"\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.11"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
